<!DOCTYPE html>
<html>
<head>
{{template "common_header.html" .}}
</head>
<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="javascript:void(0);">首页</a>
        <a href="">系统管理</a>
        <a><cite>账号管理</cite></a>
    </span>
    <a class="layui-btn layui-btn-normal layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn layui-btn-danger" id="all-item-delete"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn layui-btn-normal" onclick="x_admin_show('添加账号','/addAdmin', 500, 530)"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：{{.total}} 条</span>
    </xblock>
    <table class="layui-table">
        <colgroup>
            <col width="50">
            <col width="100">
            <col>
            <col>
            <col width="110">
            <col width="100">
            <col width="165">
            <col width="165">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align:center;">账号</th>
            <th style="text-align:center;">姓名</th>
            <th style="text-align:center;">手机号</th>
            <th style="text-align:center;">超级管理员</th>
            <th style="text-align:center;">状态</th>
            <th style="text-align:center;">创建时间</th>
            <th style="text-align:center;">更新时间</th>
            <th style="text-align:center;">操作</th>
        </tr>
        </thead>
        <tbody>
        {{range $index,$item := .adminList}}
        <tr style="text-align:center;">
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{{$item.id}}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{{$item.account}}</td>
            <td>{{$item.name}}</td>
            <td>{{$item.phone}}</td>
            <td>
            {{if eq $item.is_super 1}}<span class="layui-badge layui-bg-blue">是</span>{{else}}<span class="layui-badge layui-bg-gray">否</span>{{end}}
            </td>
            <td>
            {{if eq $item.status 0}}<span class="layui-badge layui-bg-blue">正常</span>{{else}}<span class="layui-badge layui-bg-gray">禁用</span>{{end}}
            </td>
            <td>{{$item.create_date}}</td>
            <td>{{$item.update_date}}</td>
            <td>
                <button class="layui-btn layui-btn-sm layui-btn-normal btn-float" onclick="x_admin_show('编辑账号','/updateAdmin?id={{$item.id}}', 500, 530)">编辑</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger item-model-delete" adminid="{{$item.id}}">删除</button>
            </td>
        </tr>
        {{end}}
        </tbody>
    </table>
    {{template "pager.html" .}}
</div>
{{template "common_js.html" .}}
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
    });

    $(function () {
        $('.item-model-delete').click(function () {
            var adminid = $(this).attr("adminid");
            var mylayer = layer.open({
                title: '删除账号',
                btn: ['确定', '取消'],
                content: '你确定要删除这个账号吗？',
                yes: function(index, layero){
                    var url = '/doDeleteAdmin';
                    var data = {
                        adminid:adminid
                    };
                    $.post(url, data, function(resp) {
                        if(resp.en == 200) {
                            layer.msg(resp.em);
                            setTimeout(function(){
                                window.location = "/adminList";
                            },1000);
                        } else {
                            layer.msg(resp.em);
                            layer.close(mylayer);
                        }
                    });
                },
            });
        });

        // 批量删除账号
        $('#all-item-delete').click(function () {
            var ids = new Array();
            $('.layui-form-checked').each( function( index, val) {
                var id = $(val).attr('data-id');
                if(id !== undefined && id !== '') {
                    ids.push(id);
                }
            });
            if(ids.length === 0) {
                return;
            }
            var mylayer = layer.open({
                title: '删除账号',
                btn: ['确定', '取消'],
                content: '你确定要删除已选中的账号吗？',
                yes: function(index, layero){
                    var url = '/doDeleteAdminBatch';
                    var data = {
                        ids:ids.join(",")
                    };
                    $.post(url, data, function(resp) {
                        if(resp.en == 200) {
                            layer.msg(resp.em);
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        } else {
                            layer.msg(resp.em);
                            layer.close(mylayer);
                        }
                    });
                },
            });
        });

    });
</script>
{{template "pager_js.html" .}}
</body>
</html>